//
//  DYJingquDaifukuanVC.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/2/4.
//  Copyright © 2021 叁拾叁. All rights reserved.



import UIKit

class DYJingquDaifukuanVC: SYBaseViewController , UITableViewDelegate, UITableViewDataSource{
    
    
    var bottom: DYDaifukuanBottom!
    var model: RYDingdanModel!
    
    let renyang: UIImageView = {
        let v: UIImageView = UIImageView()
        v.image = UIImage(named: "jingqu_daifukuan")
        return v
    }()
    
    let statusLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor.white
        v.font = 18.autoBoldFontSize()
        v.text = "待付款"
        return v
    }()
    
    let shuomingLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor.white
        v.font = 12.autoFontSize()
        v.text = "剩余支付时间   28:44"
        return v
    }()
    
    
    var tableView: UITableView!
    
    var id: Int = 1
    
    init(id: Int) {
        super.init(nibName: nil, bundle: nil)
        self.id = id
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupTopView()
        setTableView()
        self.title = "订单详情"
        self.view.backgroundColor = Constant.bgViewColor
        self.getData(id)
    }
    
    func getData(_ id: Int) {
        requestVM.baseRequest(disposeBag: dispose, type: .dy_jingquDingdanDetail(id: "\(id)"), modelClass: SGBaseModel<RYDingdanModel>.self) {[weak self] (res) in
            if let `self` = self {
                self.model = res.data
                self.tableView.reloadData()
            }
            
        } Error: {
            
        }
    }
    
    
    
    func setupTopView() {
        view.addSubview(renyang)
        renyang.addSubview(statusLb)
        renyang.addSubview(shuomingLb)
        renyang.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(NAV_HEIGHT)
            make.left.right.equalToSuperview()
            make.height.equalTo(160.autoWidth())
        }
        statusLb.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(19.autoWidth())
            make.left.equalToSuperview().offset(16.autoWidth())
            make.height.equalTo(18.autoWidth())
        }
        shuomingLb.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(49.autoWidth())
            make.left.equalToSuperview().offset(16.autoWidth())
            make.height.equalTo(12.autoWidth())
        }
        
        
        bottom = DYDaifukuanBottom(frame: CGRect(x: 0, y: SCREEN_HEIGHT - 56.autoWidth() - BOTTOM_SAFE_HEIGHT, width: SCREEN_WIDTH, height: 56.autoWidth()))
        bottom.currentVC = self
        view.addSubview(bottom)
        
    }

    func setTableView() {
        
        //创建表格视图
        self.tableView = UITableView(frame: CGRect(x: 15.autoWidth(), y: NAV_HEIGHT + 86.autoWidth(), width: SCREEN_WIDTH-30.autoWidth(), height: SCREEN_HEIGHT-NAV_HEIGHT-BOTTOM_SAFE_HEIGHT-86.autoWidth() - 56.autoWidth()), style:.grouped)
        self.tableView.separatorStyle = .none
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.backgroundColor = .clear
        self.tableView!.register(DYJQYIngfuCell.self, forCellReuseIdentifier: "DYJQYIngfuCell")
        self.tableView!.register(DYJQDDInfoCell.self, forCellReuseIdentifier: "DYJQDDInfoCell")
        self.tableView!.register(DYJQTuigaiCell.self, forCellReuseIdentifier: "DYJQTuigaiCell")
        self.tableView!.register(DYJQWentiCell.self, forCellReuseIdentifier: "DYJQWentiCell")
        self.tableView!.register(DYJQDetailCell.self, forCellReuseIdentifier: "DYJQDetailCell")
        
        self.view.addSubview(self.tableView!)
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row == 0 {
            let cell: DYJQYIngfuCell? = tableView.dequeueReusableCell(withIdentifier: "DYJQYIngfuCell") as? DYJQYIngfuCell
            cell?.selectionStyle = .none
            if nil != self.model {
                
                cell?.configure(model)
            }
            return cell!
        } else if indexPath.row == 1{
            let cell: DYJQDDInfoCell? = tableView.dequeueReusableCell(withIdentifier: "DYJQDDInfoCell") as? DYJQDDInfoCell
            cell?.selectionStyle = .none
            cell?.currentVC = self
            if nil != self.model {
                
                cell?.configure(model)
            }
            return cell!
        } else if indexPath.row == 2{
            let cell: DYJQTuigaiCell? = tableView.dequeueReusableCell(withIdentifier: "DYJQTuigaiCell") as? DYJQTuigaiCell
            cell?.selectionStyle = .none
            cell?.currentVC = self
            if nil != self.model {
                
                cell?.configure(model)
            }
            
            return cell!
        } else if indexPath.row == 3{
            
            let cell: DYJQWentiCell? = tableView.dequeueReusableCell(withIdentifier: "DYJQWentiCell") as? DYJQWentiCell
            cell?.selectionStyle = .none
            cell?.currentVC = self
            if nil != self.model {
                
                cell?.configure(model)
            }
            
            return cell!
        } else {
            
            let cell: DYJQDetailCell? = tableView.dequeueReusableCell(withIdentifier: "DYJQDetailCell") as? DYJQDetailCell
            cell?.selectionStyle = .none
            cell?.currentVC = self
            if nil != self.model {
                
                cell?.configure(model)
            }
            
            return cell!
        }
        
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("didSelectRowAt")
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        
        let v = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 0.01))
        return v
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.01
    }
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let v = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 0.01))
        return v
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.01
    }
}
